<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <!--[if lt IE 9]>
    <script src="../../js/geological/html5shiv.min.js"></script>
    <script src="../../js/geological/respond.min.js"></script>
    <![endif]-->
    <title>导航管理</title>
    <style>
        .nicescroll-rails.nicescroll-rails-vr{
            background: transparent!important;
            left:2.715rem!important;
        }
    </style>
</head>
<body>
        <div class="right-top-tools" style="height:50px">
            <div class="zd-tab clearfix" style="height:50px">
               <span style="color:#3c619e;font-weight: bold">导航管理  </span>
            </div>
        </div>
		<div class="table_filter"  style="height:50px;text-align:left;padding-top:6px; margin-top:30px">
			<div class="dataTables_filter" id="searchDiv">
				<input style="width: 200px;" placeholder="请输入用户姓名" id="likeFilter" name="likeFilter" class="form-control" type="search" likeoption="true">
				<div class="btn-group" style="margin-left:6px">
					<button type="button" class="btn btn-primary" data-btn-type="search" onclick="search()">查询</button>
					<button type="button" class="btn btn-default" data-btn-type="reset" onclick="likeFilterReset()">重置</button>
				</div>
				<div class="btn-group" style="float:right">
					<button id="menu_new" type="button" class="btn btn-default" data-btn-type="add">新增</button>
					<button id="menu_edit" type="button" class="btn btn-default" data-btn-type="edit">编辑</button>
					<button id="menu_delete" type="button" class="btn btn-default" data-btn-type="delete">删除</button>
				</div>
			</div>
		</div>
      
        <div class="table-container" style="margin-top:0px" >
            <table id="menutable" class="display" cellspacing="0" width="100%">
                <thead>
                <tr>
                    <th>菜单名称</th>
                    <th>菜单编码</th>
                    <th>级别编码</th>
                    <th>菜单类别</th>
                    <th>URL</th>
                    <th>上级菜单</th>
                </tr>
                </thead>
            </table>
        </div>

<script type="text/javascript">
var Dtable_menuInfo = null;
	function search(){
		Dtable_menuInfo.ajax.reload()
	}
	function likeFilterReset(){
		$("#likeFilter").val("")
		Dtable_menuInfo.ajax.reload()
	}
    $(document).ready(function(){
    	var _pagesize =10;
    	Dtable_menuInfo = $('#menutable').DataTable( {
            "info":0,
            "pageLength": _pagesize,
            "lengthChange":false,
            "searching":false,
            "ordering":true,
            "processing": true,
            "serverSide": true,
            "ajax": { 
            	url: "../../tbl_function/list",  
            	type: "post",
            	contentType: "application/json",
                dataType: "json",
                data: function( data ) {
                	if( data.order && data.order.length > 0 && data.columns && data.columns.length > 0 ){
                		data.orderIndex = data.order[0].column;
                		if( data.columns.length >= ( data.orderIndex + 1 )){
                			data.orderColName = data.columns[data.orderIndex].data;
                		}
                		data.orderType = data.order[0].dir;
                	}
                	if( $("#likeFilter").val() != null && $("#likeFilter").val() != "" ){
	            		data.likeFilter = $("#likeFilter").val();
	            	}
                    data.page = data.start/data.length + 1;
                    data.pagesize = _pagesize;
                    return JSON.stringify(data);
                },
                dataSrc: function ( json ) {
                	json.recordsTotal = json.pagination.totalRecord;
                	json.recordsFiltered = json.pagination.totalRecord;
                	return json.data;
                }
            },
            "columns": [
                { "data": "name" },
                { "data": "code" },
                { "data": "levelcode" },
                { "data": "functype" },
                { "data": "url" },
                { "data": "parent_id" }
            ],
            "order": [[ 2, "asc" ]],
            "language": {
                "paginate": {
                    "next": "下一页",
                    "previous": "上一页",
                }
            }
        } );
        
        $('#menutable tbody').on( 'click', 'tr', function () {
            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
            }else {
                $('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }
        } );
        
        $("#menu_new").click( function(){
	    	global.showModal("添加新用户", "um/function_create.html");
	    });
        
        $("#menu_edit").click(function(){
	    	if( Dtable_menuInfo.rows('.selected').data().length == 0 ){
	    		global.alert('请选择一条您需要编辑的信息！');
	    	}else{
	    		global.showModal("编辑用户信息", "um/function_edit.html");
	    	}	    	
	    });
        
        $("#menu_delete").click(function(){
	    	if( Dtable_menuInfo.rows('.selected').data().length == 0 ){
	    		global.alert('请选择一条您需要编辑的信息！');
	    	}else{
	    		$.confirm({
	        	    title: "删除操作确认！",
	        	    content: "您确认需要删除这一用户条信息吗，请谨慎操作，数据可能无法恢复！",
	        	    buttons: {
	        	    	confirm:{
	        	    		btnClass: 'btn-blue',
	        	    		text: '直接删除', // Some Non-Alphanumeric characters
		                    action: function(){
		                    	var id = Dtable_menuInfo.rows('.selected').data()[0].id;
		    		    		var url = "../../tbl_function/" + id;
		    		    		$.ajax({
		    		    			  url: url,
		    		    			  type : 'delete',
		    		    			  async : false,
		    		    			  contentType: "application/json; charset=utf-8",
		    		    			  dataType: "json",
		    		    			  success: function(json) {
		    		    				 global.alert( json.message );
		    		    				 $("#system_main").load("um/function_list.html");
		    		    			  }
		    		    		});
		                    }
	        	    	},
	        	    	cancel: {
	        	    		text: '暂不删除',
	        	        },
	        	    }
	        	});
	    	}
	    });
    });
</script>
</body>
</html>